/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license.
 * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt 
 * for the full text of the license. */


/**
 * Move a feature with a drag.
 * 
 * @class
 * @requires OpenLayers/Control.js
 * @requires OpenLayers/Handler/Drag.js
 * @requires OpenLayers/Handler/Feature.js
 */
	OpenLayers.Control.DragMarker = OpenLayers.Class.create();
	OpenLayers.Control.DragMarker.prototype = 
	  OpenLayers.Class.inherit(OpenLayers.Control.DragFeature, 
	  {
		initialize: function(layer, options) 
		{
			OpenLayers.Control.prototype.initialize.apply(this, [options]);
			this.layer = layer;
			this.handlers = 
			{
				drag: new OpenLayers.Handler.Drag
				(	this, OpenLayers.Util.extend
					({	
							down: this.downFeature,
							move: this.moveFeature,
							up: this.upFeature,
							out: this.cancel,
							done: this.doneDragging
					 }, this.dragCallbacks
					)
				),
				feature: new OpenLayers.Handler.Marker
				(	this, this.layer, OpenLayers.Util.extend
					({
							over: this.overFeature,
							out: this.outFeature
					 }, this.featureCallbacks
					), {	geometryTypes: this.geometryTypes	}
				)
			};
		}, 
 
		moveFeature: function(pixel) 
		{
						//alert((pixel.x - this.lastPixel.x) +"  |  "+ (pixel.y -this.lastPixel.y));
			var px = this.feature.icon.px.add(pixel.x - this.lastPixel.x, pixel.y - this.lastPixel.y);
			this.feature.moveTo(px);
			//this.feature.Popup.moveTo(px);
			this.lastPixel = pixel;
			this.onDrag(this.feature, pixel);
		},
			
		CLASS_NAME: "OpenLayers.Control.DragMarker"
	});